<?php
/**
 * 变量输出标签解析
 *
 * @author zyb
 */
class outinTag {

     /**
      * @param outtype 输出类型　
      * @param isbuffer 输出是否缓存
      * @param alias 别名
      * @param var 变量名
      * @param value 选中值
      * @param default 默认显示
      * @param style 加载css样式
      * **/

     public function cate($options) {
      	$data=null;
     	$options['outtype'] =isset($options['outtype']) ? trim($options['outtype']) : 'select';  //输出类型　
     	$options['value'] =isset($options['value']) ? trim($options['value']) : null; //是否选中
     	$options['alias'] =isset($options['alias']) ? trim($options['alias']) : null; //别名
     	$options['order'] =isset($options['order']) ? trim($options['order']) : 'ordid asc'; //排序
     	$options['default'] =isset($options['default']) ? trim($options['default']) : '---请选择---'; //别名
     	$options['var'] =isset($options['var']) ? trim($options['var']) : 	$options['alias']; //变量名
     	$options['style'] =isset($options['style']) ? trim($options['style']) :''; //变量名
     	$options['where'] = isset($options['where']) ? trim($options['where']) : '';

        switch ($options['outtype']) {    //判断
			case 'select':
						   $tarr=D('item_cate')->get_var($options['var']);
						   if(!$options['alias'])$options['alias']=$options['var'];
						   $data='<select name="'.$options['alias'].'" '.$options['style'] .'><option value="">'.$options['default'].'</option>';
						   foreach($tarr as $k=>$v){    //判断所选变量
						   	     $seleted='';
						   	     if(($options['value']!=null)&&($v['variable']==$options['value']))$seleted='selected="true"';
						         $data.='<option value="'.$v['variable'].'" '.$seleted.' >|--&nbsp;&nbsp;&nbsp;'.$v['name'].'</option>';
						   }
						   $data.='</select>';
						   return $data;

				break;
			 case  'checkbox':
                             $tarr=D('item_cate')->get_var($options['var']);
                             if(!$options['alias'])$options['alias']=$options['var'];
                             $data='';
                             foreach($tarr as $k=>$v){    //判断变量值相等
                                    $checked='';
                                    if($options['value']&& in_array($v['variable'],explode(',',$options['value'])))$checked='checked="true"';
                                    $data.='<input type="checkbox" name="'.$options['alias'].'[]" '.$checked.' value="'.$v['variable'].'"/>'.$v['name'].'&nbsp;&nbsp;';
                             }
                             return $data;
			    break;
			 case  'checkinput':
                             if(!F('checkinput_isbuffer')){  //判断是否缓存
	                             $tarr=D('item_cate')->get_var($options['var']);
	                             if(!$options['alias'])$options['alias']=$options['var'];
	                             if(!$options['value']){
	                             	 foreach($tarr as $k=>$v)$options['value'].=$v['variable'].',';
	                             }
	                             $data='';
	                             foreach($tarr as $k=>$v){    //判断变量值相等
	                                    $checked='';
	                                    if($options['value']&& in_array($v['variable'],explode(',',$options['value']))){
	                                    	$checked='';
	                                        $data.='<a href="javascript:void(0);" onclick="selectarrt(this);" '.$checked.' data-v="'.$v['variable'].'"/>'.$v['name'].'</a>';
	                                    }
	                             }
	                             F('checkinput_isbuffer',$data);
                             }else{
                             	$data=F('checkinput_isbuffer');
                             }
                             return $data;
			    break;
		   case  'radio':
                             $tarr=D('item_cate')->get_var($options['var']);
                             if(!$options['alias'])$options['alias']=$options['var'];
                             $data='';
                             foreach($tarr as $k=>$v){    //判断变量值相等
                                    $checked='';
                                    if( in_array($v['variable'],explode(',',$options['value'])))$checked='checked="true"';
                                    $data.='<input type="radio"  '.$options['style'].' name="'.$options['alias'].'" '.$checked.' value="'.$v['variable'].'"/>'.$v['name'].'&nbsp;&nbsp;';
                             }
                             return $data;
			    break;
             case   'name': //获取变量名
							      $tarr=D('item_cate')->get_var($options['var']);
							      foreach($tarr as $k=>$v){
							         	if($v['variable']==$options['value']){
							         		   $data= $v['name'];
							         		    break;
							         	}
							        }
							return $data;
                break;
              case 'id':    //获取ID
                            $data=D('item_cate')->where(array('variable'=>$options['var']))->getField('id');
							if(!$data)$data=14;
							return $data;
			   break;

			   case 'list':  //获取变量列表
                            $options['field'] = isset($options['field']) ? trim($options['field']) : '*';
					        $options['num'] = isset($options['num']) ? intval($options['num']) :0;
					        $options['isbuffer'] =intval($options['isbuffer']) ?1 :0;
					        if($options['isbuffer']&&F($options['alias'])){  //生成缓存
                                  return F($options['alias']);
					        }else{
					            $mod =D('item_cate');
					            $map['pid']=$mod->where(array('variable'=>$options['var']))->getField('id');
					            $map['status'] = 1;
					            $options['where'] && $map['_string'] = $options['where'];
					            $select = $mod->field($options['field']); //字段
					            $select->where($map); //条件
					            $options['num'] && $select->limit($options['num']); //个数
					            $select->order($options['order']); //排序
					            $data = $select->select();
					            if($options['isbuffer'])F($options['alias'],$data);
					        }
						   return $data;
				break;
			default:

				break;
		}
        return $data;
    }


     /**
      * @param pid 父类id　
      * @param order 排序
      * @param where 条件
      * @param num 数量
      * **/

     public function flink($options) {
      	$data=null;

     	$options['pid'] =isset($options['pid']) ? trim($options['pid']) : null; //父类id
     	$options['order'] =isset($options['order']) ? trim($options['order']) : 'ordid asc'; //排序
     	$options['where'] = isset($options['where']) ? trim($options['where']) : '';
		$options['num'] = isset($options['num']) ? intval($options['num']) :0;
		$options['field'] = isset($options['field']) ? trim($options['field']) : '*';

        $mod =D('flink');
        $map['status'] = 1;
        $map['cate_id'] = $options['pid'];
        $options['where'] && $map['_string'] = $options['where'];
        $select = $mod->field('url,name'); //字段
        $select->where($map); //条件
        $options['num'] && $select->limit($options['num']); //个数
        $select->order($options['order']); //排序
        $data['list'] = $select->select();
        $data['name'] = D('flink_cate')->where(array('id'=>$options['pid'],'status'=>1))->getField('name');

        return $data;

}





}